import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";

import { resolve } from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    createSvgIconsPlugin({
      // 要缓存的图标文件夹
      iconDirs: [resolve(__dirname, "src/assets/svgs")],
      // 执行 icon name 的格式
      symbolId: "icon-[name]",
    }),
  ],
  resolve: {
    alias: {
      "@": resolve("src"),
    },
  },
  server: {
    port: 80,
    host: "0.0.0.0",
    proxy: {
      "/dev-api": {
        // 灰度
        target: "https://gateway-huidu.huimaisoft.com",
        // 测试
        // target: "https://gateway-dev-supply.huimaisoft.com",
        // 正式
        // target: "https://scm-gw.huimaisoft.com",
        changeOrigin: true,
        ws: true,
        rewrite: (path) => path.replace(new RegExp("^" + "/dev-api"), ""),
      },
    },
  },
  css: {
    // css 预处理器
    preprocessorOptions: {
      // provide global variables
      less: {
        additionalData: `
          @import "@/styles/mixins.less";
          @import "@/styles/variables.less";
        `,
      },
    },
  },
});
